package com.example.teaculture.application;

import android.app.Application;
import android.content.res.Configuration;
import android.util.Log;

import androidx.annotation.NonNull;

import com.example.teaculture.model.Favor;
import com.example.teaculture.model.Headline;
import com.example.teaculture.model.TeaBusiness;
import com.example.teaculture.model.TeaInfo;
import com.example.teaculture.model.Teaknown;
import com.example.teaculture.tools.JsoupUtils;
import com.yechaoa.yutils.YUtils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class MyApplication extends Application {

    public static MyApplication mApp;

    public Favor favor = new Favor();
    public List<TeaInfo> list = new ArrayList<>();
    public List<Teaknown> teaKnowns = new ArrayList<>();
    public List<Headline> teaHeadlines = new ArrayList<>();
    public List<TeaInfo> encyclopedias = new ArrayList<>();
    public List<TeaInfo> businesses = new ArrayList<>();

    private static final String BASE_URL = "https://www.ybtea.cn/";

    public static MyApplication getInstance() {
        return mApp;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mApp = this;
        //初始化YUtils
        YUtils.init(this);

        initData();
    }

    public void initData() {
        list = JsoupUtils.getTeaInfo("https://www.ybtea.cn/","cyzl/lvcha/");
        try {
            teaKnowns = JsoupUtils.getTeaknown("https://chaaowang.com/fenlei/changshi","/page/2");
            teaHeadlines =JsoupUtils.getHeadline("http://cha.quanxi.cc/toutiao/TypesList/7030", "/1");
            encyclopedias=JsoupUtils.getTeaEncyclopedia("https://chaaowang.com/fenlei/changshi","/page/1");
            businesses = JsoupUtils.getTeaBusiness(0);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }
}
